﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;

namespace RiskMan.DataClass.Models.Plaza_II.FortsVmRepl
{
    /// <summary>
    /// Таблица 64. Поля таблицы fut_vm - Вариационная маржа по фьючерсам
    /// </summary>
    public class FutVm:INotifyPropertyChanged
    {
        #region private

        private long _replId;
        private long _replRev;
        private long _replAct;
        private int _isinId;
        private int _sessId;
        private string _clientCode;
        private Decimal _vm;
        private Decimal _vmReal;

        #endregion

        #region public

        /// <summary>
        /// Служебное поле подсистемы репликации
        /// </summary>
        public long ReplId
        {
            get { return _replId; }
            set
            {
                if (_replId != value)
                {
                    _replId = value;
                    RaisePropertyChanged("ReplId");
                }
            }
        }

        /// <summary>
        /// Служебное поле подсистемы репликации
        /// </summary>
        public long ReplRev
        {
            get { return _replRev; }
            set
            {
                if (_replRev != value)
                {
                    _replRev = value;
                    RaisePropertyChanged("ReplRev");
                }
            }
        }

        /// <summary>
        /// Служебное поле подсистемы репликации
        /// </summary>
        public long ReplAct
        {
            get { return _replAct; }
            set
            {
                if (_replAct != value)
                {
                    _replAct = value;
                    RaisePropertyChanged("ReplAct");
                }
            }
        }

        /// <summary>
        /// Уникальный числовой идентификатор инструмента
        /// </summary>
        public int IsinId
        {
            get { return _isinId; }
            set
            {
                if (_isinId != value)
                {
                    _isinId = value;
                    RaisePropertyChanged("IsinId");
                }
            }
        }
        
        /// <summary>
        /// 
        /// </summary>
        public int SessId
        {
            get { return _sessId; }
            set
            {
                if (_sessId != value)
                {
                    _sessId = value;
                    RaisePropertyChanged("SessId");
                }
            }
        }
        
        /// <summary>
        /// 
        /// </summary>
        public string ClientCode
        {
            get { return _clientCode; }
            set
            {
                if (_clientCode != value)
                {
                    _clientCode = value;
                    RaisePropertyChanged("ClientCode");
                }
            }
        }
        
        /// <summary>
        /// 
        /// </summary>
        public Decimal Vm
        {
            get { return _vm; }
            set
            {
                if (_vm != value)
                {
                    _vm = value;
                    RaisePropertyChanged("Vm");
                }
            }
        }
        
        /// <summary>
        /// 
        /// </summary>
        public Decimal VmReal
        {
            get { return _vmReal; }
            set
            {
                if (_vmReal != value)
                {
                    _vmReal = value;
                    RaisePropertyChanged("VmReal");
                }
            }
        }

        #endregion


        #region event PropertyChangedEventHandler

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        #region Processing
        public static FutVm ParseFutVm(Dictionary<String, String> relation)
        {
            FutVm tmp = new FutVm();
            tmp.Parse(relation);
            return tmp;
        }

        public void Parse(Dictionary<String, String> relation)
        {
            foreach (String field in relation.Keys)
            {
                String value = relation[field];

                switch (field)
                {
                    case "replID": long.TryParse(value, out _replId); break;
                    case "replRev": long.TryParse(value, out _replRev); break;
                    case "replAct": long.TryParse(value, out _replAct); break;
                    case "isin_id": int.TryParse(value, out _isinId); break;
                    case "sess_id": int.TryParse(value, out _sessId); break;
                    case "client_code": _clientCode = value; break;
                    case "vm": Decimal.TryParse(value, NumberStyles.Number, CultureInfo.GetCultureInfo("en-US"), out _vm); break;
                    case "vm_real": Decimal.TryParse(value, NumberStyles.Number, CultureInfo.GetCultureInfo("en-US"), out _vmReal); break; 
                };
            }
        }

        public static void AddValueToObsColFutVm(FutVm inst)
        {
            MainWindow.StaticLevel._dataProvider.FutVmList.Add(inst);
        }
        #endregion
    }
}
